package controller;

import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

@Controller
public class LoginController {

//    @RequestMapping("/showLogin")
//    public ModelAndView show(){
//        System.out.println("LoginController.show()");
//        return new ModelAndView("login");
//    }

    @RequestMapping("/login")
    public String login(String username, String password, Map map, HttpSession session){
        System.out.println("LoginController.login()");
        System.out.println("username = " + username + ", password = " + password);

        if("abc".equals(username)&&"123".equals(password)){
            session.setAttribute("user",username);
            return "redirect:/showSuccess";
        }

        map.put("message","用户名或密码错误");


        return "login";
//        return "forward:/WEB-INF/jsp/login.jsp";
    }
}
